package com.work.formaldehyde.activityadapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.work.formaldehyde.R;
import com.work.formaldehyde.model.JianCeDateModel;
import com.work.formaldehyde.util.ApiUtils;

import java.text.DecimalFormat;
import java.util.ArrayList;

public class JianCeDateAdapter extends BaseAdapter {
    ArrayList<JianCeDateModel.data> list;
    Context context;

    public JianCeDateAdapter(ArrayList<JianCeDateModel.data> list, Context context) {
        // TODO Auto-generated constructor stub
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list != null ? list.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return list != null ? list.get(position) : 0;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        convertView = LayoutInflater.from(context).inflate(R.layout.item_jiancedate, null);
        init i = new init();
        i.zhuwotext = convertView.findViewById(R.id.zhuwotext);
        i.wendutext = convertView.findViewById(R.id.wendutext);
        i.shidutext = convertView.findViewById(R.id.shidutext);
        i.jiaquantext = convertView.findViewById(R.id.jiaquantext);
        i.timetext = convertView.findViewById(R.id.timetext);
        String money = list.get(position).getHcho();
        float scale = Float.valueOf(money);
        DecimalFormat fnum = new DecimalFormat("##0.00");
        String dd = fnum.format(scale);
        i.zhuwotext.setText(list.get(position).getRoom());
        i.wendutext.setText(list.get(position).getTemp());
        i.shidutext.setText(list.get(position).getHumidity());
        i.jiaquantext.setText(dd+"");
        String str = list.get(position).getTimes();
        String strtime = str.substring(0, 10);
        i.timetext.setText(strtime);
        convertView.setTag(i);
        return convertView;
    }

    public static class init {
        //首页list的子控件
        TextView zhuwotext, wendutext, shidutext, jiaquantext, timetext;
    }
}

